Here is a method that I wrote to create attribute definitions:
//Method for creating attribute definitions
void createAttributeDefinitions(){
//Grab selected project
Project p = proj
//Iterate through items in current project
Item item = (Item null)
string iType = ""
Module m = null
for item in p do {
//Determine type of item
iType = type(item)
if (iType == "Formal" && name(item) == "TestModule") { //item is a formal module
//Open module for reading
m = read(fullName(item), false)
//Open module for editing
m = edit(fullName(m), true)
//Set as current module
current = m
//Ensure all attribute types exist
t = 0
while(t < numOfTypes){
//Extract property
AttrType a = get(typeArray,t,1)
AttrType at = find (m, a.name)
//Determine if attribute exists
if (null at){ //attribute does not exist in current module
//Create attribute type
createAttributeType(a)
}
else{}
t++
}
//Iterate through elements in array
i = 0
while(i < numOfElements){
//Set attribute definition
AttrDef__ a = get(keyArray, i, 1)
//Create attribute
AttrDef ad = create a
//Modify attribute to include description
if(!null ad)
ad = modify(ad, setDescription, "Key Attribute")
i++
}
//Save changes
save(m)
//Close module
close(m)
}
else{}
}
}
meherts - Mon Jun 21 13:36:40 EDT 2010 |
Re: Awkward looping behavior
If I remove these two lines of code ... save(m) close(m)
|
Re: Awkward looping behavior meherts - Mon Jun 21 14:31:04 EDT 2010
If I remove these two lines of code ... save(m) close(m)
Apparently you can't even do this with skip lists ... I tried to iterate through a skip list and then make the changes and such, but it failed in a similar manner:
//Method for creating attributes
void createAttributes(){
//String for manipulation
string str = ""
//Iterate through skip list
Module m = null
for str in skpLst do{
//Key
string uID = (string key skpLst)
//Grab item
Item item = itemFromID(uID)
//Open module for reading
m = read(fullName(item), false)
//Open module for editing
m = edit(fullName(m), true)
//Set as current module
current = m
//Ensure all attribute types exist
t = 0
while(t < numOfTypes){
//Extract property
AttrType a = get(typeArray,t,1)
AttrType at = find (m, a.name)
//Determine if attribute exists
if (null at){ //attribute does not exist in current module
//Create attribute type
createAttributeType(a)
}
else{}
t++
}
//Iterate through elements in array
i = 0
while(i < numOfElements){
//Set attribute definition
AttrDef__ a = get(keyArray, i, 1)
//Create attribute
AttrDef ad = create a
//Modify attribute to include description
if(!null ad)
ad = modify(ad, setDescription, "Key Attribute")
i++
}
//Save changes
save(m)
//Close module
close(m)
}
}
//Method for populating skip list
void createSkpLst(){
//Grab selected project
Project p = proj
//Iterate through items in current project
Item item = (Item null)
string iType = ""
Module m = null
for item in p do {
//Determine type of item
iType = type(item)
if (iType == "Formal" && name(item) == "TModule") { //item is a formal module
//Put into skip list
put(skpLst,uniqueID(item),uniqueID(item))
}
else{}
}
//Create Attributes
createAttributes()
}
|
Re: Awkward looping behavior meherts - Mon Jun 21 15:41:55 EDT 2010
Apparently you can't even do this with skip lists ... I tried to iterate through a skip list and then make the changes and such, but it failed in a similar manner:
//Method for creating attributes
void createAttributes(){
//String for manipulation
string str = ""
//Iterate through skip list
Module m = null
for str in skpLst do{
//Key
string uID = (string key skpLst)
//Grab item
Item item = itemFromID(uID)
//Open module for reading
m = read(fullName(item), false)
//Open module for editing
m = edit(fullName(m), true)
//Set as current module
current = m
//Ensure all attribute types exist
t = 0
while(t < numOfTypes){
//Extract property
AttrType a = get(typeArray,t,1)
AttrType at = find (m, a.name)
//Determine if attribute exists
if (null at){ //attribute does not exist in current module
//Create attribute type
createAttributeType(a)
}
else{}
t++
}
//Iterate through elements in array
i = 0
while(i < numOfElements){
//Set attribute definition
AttrDef__ a = get(keyArray, i, 1)
//Create attribute
AttrDef ad = create a
//Modify attribute to include description
if(!null ad)
ad = modify(ad, setDescription, "Key Attribute")
i++
}
//Save changes
save(m)
//Close module
close(m)
}
}
//Method for populating skip list
void createSkpLst(){
//Grab selected project
Project p = proj
//Iterate through items in current project
Item item = (Item null)
string iType = ""
Module m = null
for item in p do {
//Determine type of item
iType = type(item)
if (iType == "Formal" && name(item) == "TModule") { //item is a formal module
//Put into skip list
put(skpLst,uniqueID(item),uniqueID(item))
}
else{}
}
//Create Attributes
createAttributes()
}
Thanks, m. |
Re: Awkward looping behavior meherts - Tue Jun 22 09:17:50 EDT 2010
I am not sure what you store in the keyArray, but it seems like it is objects of the type AttrDef__. Is it so?
struct MyAttrDef {};
MyAttrDef newMyAttrDef(Some parameters...);
AttrDef__ getAttrDef(MyAttrDef);
// Create list of attrdefs
MyAttrDef med = newMyAttrDef(parameters)
put(skip, i++, med)
.
.
.
// Use whats inside list and create attributes
for med in skip do
{
AttrDef__ ad__ = getAttrDef(med)
AttrDef ad = create (ad__)
}
|
Re: Awkward looping behavior |
Re: Awkward looping behavior
I think you need to include the parts of the script that populate your two main arrays, typeArray and keyArray. noError() AttrDef ad = create(...) string ErrMess = lastError() if (null ad or !null ErrMess) then print didn't create, ErrMess
int numOfTypes = 5
int t
for t in 0:numOfTypes-1 do
{ print t "\n"
}
|